<template>
  <j-modal
    :title="title"
    :width="1000"
    :visible="visible"
    :confirmLoading="confirmLoading"
    switchFullscreen
    @ok="handleOk"
    @cancel="handleCancel">
    <a-spin :spinning="confirmLoading">
      <!-- 主表单区域 -->
      <a-form :form="form">
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="京东到家订单号">
          <a-input placeholder="请输入京东到家订单号" v-decorator="['orderId', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单来源类型">
          <a-input-number v-decorator="[ 'srcInnerType', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单类型">
          <a-input-number v-decorator="[ 'orderType', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单状态">
          <a-input-number v-decorator="[ 'orderStatus', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单状态最新更改时间">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'orderStatusTime', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="下单时间">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'orderStartTime', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单成交时间">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'orderPurchaseTime', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单时效类型">
          <a-input-number v-decorator="[ 'orderAgingType', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="预计送达开始时间">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'orderPreStartDeliveryTime', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="预计送达结束时间">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'orderPreEndDeliveryTime', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="商家最晚拣货完成时间">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'pickDeadline', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单取消时间">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'orderCancelTime', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单取消备注">
          <a-input placeholder="请输入订单取消备注" v-decorator="['orderCancelRemark', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="商家编码">
          <a-input placeholder="请输入商家编码" v-decorator="['orgCode', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="买家账号">
          <a-input placeholder="请输入买家账号" v-decorator="['buyerPin', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人名称">
          <a-input placeholder="请输入收货人名称" v-decorator="['buyerFullName', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人地址">
          <a-input placeholder="请输入收货人地址" v-decorator="['buyerFullAddress', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人电话">
          <a-input placeholder="请输入收货人电话" v-decorator="['buyerTelephone', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人手机号">
          <a-input placeholder="请输入收货人手机号" v-decorator="['buyerMobile', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人真实手机号后四位">
          <a-input placeholder="请输入收货人真实手机号后四位" v-decorator="['lastFourDigitsOfBuyerMobile', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="到家配送门店编码">
          <a-input placeholder="请输入到家配送门店编码" v-decorator="['deliveryStationNo', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="商家门店编码">
          <a-input placeholder="请输入商家门店编码" v-decorator="['deliveryStationNoIsv', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="配送门店名称">
          <a-input placeholder="请输入配送门店名称" v-decorator="['deliveryStationName', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="承运商编号">
          <a-input placeholder="请输入承运商编号"
                   v-decorator="['deliveryCarrierNo', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="承运商名称">
          <a-input placeholder="请输入承运商名称" v-decorator="['deliveryCarrierName', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="承运单号">
          <a-input placeholder="请输入承运单号，通常情况下和订单号一致" v-decorator="['deliveryBillNo', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="包裹重量（单位：kg）">
          <a-input-number v-decorator="[ 'deliveryPackageWeight', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="妥投时间">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'deliveryConfirmTime', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单支付类型">
          <a-input-number v-decorator="[ 'orderPayType', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单支付渠道">
          <a-input-number v-decorator="[ 'payChannel', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="	订单商品销售价总金额">
          <a-input placeholder="请输入	订单商品销售价总金额"
                   v-decorator="['orderTotalMoney', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单级别优惠商品金额">
          <a-input
            placeholder="请输入订单级别优惠商品金额"
            v-decorator="['orderDiscountMoney', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户支付的实际订单运费">
          <a-input
            placeholder="请输入用户支付的实际订单运费"
            v-decorator="['orderFreightMoney', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="达达同城送运费(单位：分)">
          <a-input placeholder="请输入达达同城送运费(单位：分)" v-decorator="['localDeliveryMoney', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="商家支付远距离运费(单位：分)">
          <a-input placeholder="请输入商家支付远距离运费(单位：分)"
                   v-decorator="['merchantPaymentDistanceFreightMoney', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单应收运费">
          <a-input
            placeholder="请输入订单应收运费"
            v-decorator="['orderReceivableFreight', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户积分抵扣金额">
          <a-input placeholder="请输入用户积分抵扣金额" v-decorator="['platformPointsDeductionMoney', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户应付金额（单位为分）">
          <a-input
            placeholder="请输入用户应付金额（单位为分）"
            v-decorator="['orderBuyerPayableMoney', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="包装金额">
          <a-input placeholder="请输入包装金额" v-decorator="['packagingMoney', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="商家给配送员加的小费">
          <a-input
            placeholder="请输入商家给配送员加的小费"
            v-decorator="['tips', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否存在订单调整">
          <a-input placeholder="请输入是否存在订单调整"
                   v-decorator="['adjustIsExists', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="调整单编号">
          <a-input placeholder="请输入调整单编号" v-decorator="['adjustId', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="是否拼团订单">
          <a-input placeholder="请输入是否拼团订单" v-decorator="['isGroupon', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人地址定位类型">
          <a-input-number v-decorator="[ 'buyerCoordType', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人地址腾讯坐标经度">
          <a-input-number v-decorator="[ 'buyerLng', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人地址腾讯坐标纬度">
          <a-input-number v-decorator="[ 'buyerLat', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人市ID">
          <a-input placeholder="请输入收货人市ID" v-decorator="['buyerCity', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人市名称">
          <a-input placeholder="请输入收货人市名称" v-decorator="['buyerCityName', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人县(区)ID">
          <a-input placeholder="请输入收货人县(区)ID" v-decorator="['buyerCountry', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人县(区)名称">
          <a-input placeholder="请输入收货人县(区)名称" v-decorator="['buyerCountryName', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单买家备注">
          <a-input placeholder="请输入订单买家备注" v-decorator="['orderBuyerRemark', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="业务标识">
          <a-input
            placeholder="请输入业务标识"
            v-decorator="['businessTag', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="设备id">
          <a-input placeholder="请输入设备id" v-decorator="['equipmentId', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人POI信息">
          <a-input placeholder="请输入收货人POI信息" v-decorator="['buyerPoi', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订购人姓名">
          <a-input placeholder="请输入订购人姓名(此字段针对鲜花业务)" v-decorator="['ordererName', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订购人电话">
          <a-input placeholder="请输入订购人电话(此字段针对鲜花业务)" v-decorator="['ordererMobile', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="当天门店订单序号">
          <a-input placeholder="请输入当天门店订单序号" v-decorator="['orderNum', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="用户小费">
          <a-input placeholder="请输入用户小费" v-decorator="['userTip', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="收货人电话中间号有效期">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'middleNumBindingTime', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单抛入达达抢单池时间">
          <a-date-picker showTime format="YYYY-MM-DD HH:mm:ss" v-decorator="[ 'deliverInputTime', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单业务类型">
          <a-input-number v-decorator="[ 'businessType', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="商家会员VIP卡号">
          <a-input placeholder="请输入商家会员VIP卡号" v-decorator="['venderVipCardId', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单开发票标识">
          <a-input-number v-decorator="[ 'orderInvoiceOpenMark', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="处方订单处方单图片">
          <a-input placeholder="请输入处方订单处方单图片地址" v-decorator="['specialServiceTag', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单来源系统">
          <a-input
            placeholder="请输入订单来源系统"
            v-decorator="['srcOrderType', {}]"/>
        </a-form-item>
        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="订单来源系统">
          <a-input placeholder="请输入订单来源系统" v-decorator="['srcOrderId', {}]"/>
        </a-form-item>
      </a-form>
    </a-spin>
  </j-modal>
</template>

<script>
import { httpAction } from '@/api/manage'
import JDate from '@/components/jeecg/JDate'
import pick from 'lodash.pick'
import moment from 'moment'

export default {
  name: 'OmsJddjOrderModal',
  components: {
    JDate
  },
  data() {
    return {
      title: '操作',
      visible: false,
      model: {},
      labelCol: {
        xs: { span: 24 },
        sm: { span: 5 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      confirmLoading: false,
      form: this.$form.createForm(this),
      validatorRules: {},
      url: {
        add: '/oms/omsJddjOrder/add',
        edit: '/oms/omsJddjOrder/edit',
        omsJddjOrderProductList: '/oms/omsJddjOrder/queryOmsJddjOrderProductByMainId',
        omsJddjOrderInvoiceList: '/oms/omsJddjOrder/queryOmsJddjOrderInvoiceByMainId',
        omsJddjOrderDiscountList: '/oms/omsJddjOrder/queryOmsJddjOrderDiscountByMainId'
      }
    }
  },
  methods: {
    add() {
      this.edit({})
    },
    edit(record) {
      this.form.resetFields()
      this.model = Object.assign({}, record)
      //初始化明细表数据
      console.log(this.model.id)
      this.visible = true
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model, 'orderId', 'srcInnerType', 'orderType', 'orderStatus', 'orderStatusTime', 'orderStartTime', 'orderPurchaseTime', 'orderAgingType', 'orderPreStartDeliveryTime', 'orderPreEndDeliveryTime', 'pickDeadline', 'orderCancelTime', 'orderCancelRemark', 'orgCode', 'buyerPin', 'buyerFullName', 'buyerFullAddress', 'buyerTelephone', 'buyerMobile', 'lastFourDigitsOfBuyerMobile', 'deliveryStationNo', 'deliveryStationNoIsv', 'deliveryStationName', 'deliveryCarrierNo', 'deliveryCarrierName', 'deliveryBillNo', 'deliveryPackageWeight', 'deliveryConfirmTime', 'orderPayType', 'payChannel', 'orderTotalMoney', 'orderDiscountMoney', 'orderFreightMoney', 'localDeliveryMoney', 'merchantPaymentDistanceFreightMoney', 'orderReceivableFreight', 'platformPointsDeductionMoney', 'orderBuyerPayableMoney', 'packagingMoney', 'tips', 'adjustIsExists', 'adjustId', 'isGroupon', 'buyerCoordType', 'buyerLng', 'buyerLat', 'buyerCity', 'buyerCityName', 'buyerCountry', 'buyerCountryName', 'orderBuyerRemark', 'businessTag', 'equipmentId', 'buyerPoi', 'ordererName', 'ordererMobile', 'orderNum', 'userTip', 'middleNumBindingTime', 'deliverInputTime', 'businessType', 'venderVipCardId', 'orderInvoiceOpenMark', 'specialServiceTag', 'srcOrderType', 'srcOrderId'))
        // 时间格式化
        this.form.setFieldsValue({ orderStatusTime: this.model.orderStatusTime ? moment(this.model.orderStatusTime) : null })
        this.form.setFieldsValue({ orderStartTime: this.model.orderStartTime ? moment(this.model.orderStartTime) : null })
        this.form.setFieldsValue({ orderPurchaseTime: this.model.orderPurchaseTime ? moment(this.model.orderPurchaseTime) : null })
        this.form.setFieldsValue({ orderPreStartDeliveryTime: this.model.orderPreStartDeliveryTime ? moment(this.model.orderPreStartDeliveryTime) : null })
        this.form.setFieldsValue({ orderPreEndDeliveryTime: this.model.orderPreEndDeliveryTime ? moment(this.model.orderPreEndDeliveryTime) : null })
        this.form.setFieldsValue({ pickDeadline: this.model.pickDeadline ? moment(this.model.pickDeadline) : null })
        this.form.setFieldsValue({ orderCancelTime: this.model.orderCancelTime ? moment(this.model.orderCancelTime) : null })
        this.form.setFieldsValue({ deliveryConfirmTime: this.model.deliveryConfirmTime ? moment(this.model.deliveryConfirmTime) : null })
        this.form.setFieldsValue({ middleNumBindingTime: this.model.middleNumBindingTime ? moment(this.model.middleNumBindingTime) : null })
        this.form.setFieldsValue({ deliverInputTime: this.model.deliverInputTime ? moment(this.model.deliverInputTime) : null })
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      const that = this
      // 触发表单验证
      this.form.validateFields((err, values) => {
        if (!err) {
          that.confirmLoading = true
          let httpurl = ''
          let method = ''
          if (!this.model.id) {
            httpurl += this.url.add
            method = 'post'
          } else {
            httpurl += this.url.edit
            method = 'put'
          }
          let formData = Object.assign(this.model, values)
          //时间格式化
          formData.orderStatusTime = formData.orderStatusTime ? formData.orderStatusTime.format('YYYY-MM-DD HH:mm:ss') : null
          formData.orderStartTime = formData.orderStartTime ? formData.orderStartTime.format('YYYY-MM-DD HH:mm:ss') : null
          formData.orderPurchaseTime = formData.orderPurchaseTime ? formData.orderPurchaseTime.format('YYYY-MM-DD HH:mm:ss') : null
          formData.orderPreStartDeliveryTime = formData.orderPreStartDeliveryTime ? formData.orderPreStartDeliveryTime.format('YYYY-MM-DD HH:mm:ss') : null
          formData.orderPreEndDeliveryTime = formData.orderPreEndDeliveryTime ? formData.orderPreEndDeliveryTime.format('YYYY-MM-DD HH:mm:ss') : null
          formData.pickDeadline = formData.pickDeadline ? formData.pickDeadline.format('YYYY-MM-DD HH:mm:ss') : null
          formData.orderCancelTime = formData.orderCancelTime ? formData.orderCancelTime.format('YYYY-MM-DD HH:mm:ss') : null
          formData.deliveryConfirmTime = formData.deliveryConfirmTime ? formData.deliveryConfirmTime.format('YYYY-MM-DD HH:mm:ss') : null
          formData.middleNumBindingTime = formData.middleNumBindingTime ? formData.middleNumBindingTime.format('YYYY-MM-DD HH:mm:ss') : null
          formData.deliverInputTime = formData.deliverInputTime ? formData.deliverInputTime.format('YYYY-MM-DD HH:mm:ss') : null
          httpAction(httpurl, formData, method).then((res) => {
            if (res.success) {
              that.$message.success(res.message)
              that.$emit('ok')
            } else {
              that.$message.warning(res.message)
            }
          }).finally(() => {
            that.confirmLoading = false
            that.close()
          })
        }
      })
    },
    handleCancel() {
      this.close()
    }
  }
}
</script>

<style scoped>
.ant-btn {
  padding: 0 10px;
  margin-left: 3px;
}

.ant-form-item-control {
  line-height: 0px;
}

/** 主表单行间距 */
.ant-form .ant-form-item {
  margin-bottom: 10px;
}

/** Tab页面行间距 */
.ant-tabs-content .ant-form-item {
  margin-bottom: 0px;
}
</style>